package com.tcm.ucenter.web.controller;

import com.base.core.exception.ServiceException;
import com.base.core.utils.R;
import com.tcm.ucenter.domain.dto.UserRechargeDTO;
import com.tcm.ucenter.service.UserRechargeService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ucenter/recharge")
public class UserRechargeController {

    @DubboReference(version = "0.0.1-alpha", timeout = 3000, check = false, retries = 3)
    UserRechargeService userRechargeService;

    /**
     * 根据id获取但条数据
     * @param id
     * @return
     * @throws Exception
     */
    @GetMapping("/view")
    public R view(@RequestParam("id") Long id) throws Exception {
        return R.success(userRechargeService.findById(id));
    }

    /**
     * 保存数据
     * @param userRechargeDto
     * @return
     */
    @PostMapping("/create")
    public R create(@RequestBody UserRechargeDTO userRechargeDto){
        try{
            userRechargeService.create(userRechargeDto);
        }catch (ServiceException e){
            return R.fail(e.getResult().getCode(), e.getMessage());
        }catch (Exception e){
            return R.fail(e.getMessage());
        }
        return R.success();
    }

}
